#output how much time a task 4 used in CPU 0
#		context_switch(rq, prev, next); /* unlocks the rq */
#		/*
#		 * the context switch might have flipped the stack from under
#		 * us, hence refresh the local variables.
#		 */
#		cpu = smp_processor_id();

tvariable $cur_pid=-1
tvariable $cur_begin
tvariable $task_rdtsc
tvariable $task_c
tvariable $other_rdtsc
tvariable $other_c


#First
list schedule
trace 5830 if ($cpu_id==0 && $cur_pid == -1)
passcount 1
action
  teval $cur_pid = (uint64_t)((struct task_struct *)$current_task)->pid
  teval $cur_begin = $cooked_rdtsc
end

#The task that we care about
list schedule
trace 5830 if ($cpu_id==0 && $cur_pid == 4)
action
  teval $task_rdtsc = $cooked_rdtsc - $cur_begin + $task_rdtsc
  teval $task_c=$task_c+1
  teval $cur_pid = (uint64_t)((struct task_struct *)$current_task)->pid
  teval $cur_begin = $cooked_rdtsc
end

#The other task
list schedule
trace 5830 if ($cpu_id==0 && $cur_pid != 4)
action
  teval $other_rdtsc = $cooked_rdtsc - $cur_begin + $other_rdtsc
  teval $other_c=$other_c+1
  teval $cur_pid = (uint64_t)((struct task_struct *)$current_task)->pid
  teval $cur_begin = $cooked_rdtsc
end

define showall
  printf "Task: %lld %lld\n All: %lld %lld\n%.11f %.11f\n", $task_rdtsc, $task_c, $task_rdtsc + $other_rdtsc, $other_c+$task_c, (float)$task_rdtsc/(float)($task_rdtsc + $other_rdtsc), (float)$task_c/(float)($task_c + $other_c)
end
